const router = require('koa-router')()
const koaBody = require('koa-body')();
const request = require('superagent'); //不要忘记npm install
var config=require('../config/app.config');
const co = require('co')
module.exports = router.post('/queryHotActivity', koaBody, co.wrap(function*(ctx) {
    var reqparam = ctx.request.body
    var res = yield request
    .post(config.host+'/api/cms/activity/queryHotActivity')
    .send({ orgId: config.orgNo, merId: config.merchantNo, groupId: reqparam.groupId, })
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    ctx.response.body = res.body;
  })).post('/query', koaBody, co.wrap(function*(ctx) {
    // console.log(ctx.request.body);
    // => POST body
    //ctx.body = JSON.stringify(ctx.request.body);
    //console.log(ctx.body)
    // 调用远程接口获取用户授权信息
    var reqparam = ctx.request.body
    var res = yield request
    .post(config.host+'/api/cms/activity/query')
    .send({ orgId: config.orgNo, merId: config.merchantNo, currentPage: reqparam.currentPage, pageSize: reqparam.pageSize })
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    // console.log(res);
    ctx.response.body = res.body;
    // ctx.render('index', { title: 'Nunjucks', content: 'Feifeiyu yeah!' });
  })).post('/interestGroup/list', koaBody, co.wrap(function*(ctx) {
    var reqparam = ctx.request.body
    var res = yield request
    .post(config.host+'/api/cms/interestGroup/queryInterestGroup')
    .send({ orgId: config.orgNo, merId: config.merchantNo, categoryId: reqparam.categoryId, currentPage: reqparam.currentPage, pageSize: reqparam.pageSize })
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    ctx.response.body = res.body;
  })).post('/interestGroup/info', koaBody, co.wrap(function*(ctx) {
    var reqparam = ctx.request.body
    var res = yield request
    .post(config.host+'/api/cms/interestGroup/queryInterestGroupById')
    .send({ orgId: config.orgNo, merId: config.merchantNo, groupId: reqparam.groupId, customerId: reqparam.customerId })
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    ctx.response.body = res.body;
  })).post('/groupActlist', koaBody, co.wrap(function*(ctx) {
    var reqparam = ctx.request.body
    var res = yield request
    .post(config.host+'/api/cms/activity/queryGroupActivity')
    .send({ orgId: config.orgNo, merId: config.merchantNo, groupId: reqparam.groupId, actStatus: reqparam.actStatus, currentPage: reqparam.currentPage, pageSize: reqparam.pageSize })
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    ctx.response.body = res.body;
  })).post('/queryActivityInfo', koaBody, co.wrap(function*(ctx) {
    var reqparam = ctx.request.body
    var res = yield request
    .post(config.host+'/api/cms/activity/queryActivityInfo')
    .send({ orgId: config.orgNo, merId: config.merchantNo, activityId: reqparam.activityId, customerId: reqparam.customerId })
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    ctx.response.body = res.body;
  })).post('/joinGroup', koaBody, co.wrap(function*(ctx) {
    var reqparam = ctx.request.body
    var res = yield request
    .post(config.host+'/api/cms/interestGroup/customerJoinInterestGroup')
    .send({ groupId: reqparam.groupId, customerId: reqparam.customerId, customerPhone: reqparam.customerPhone })
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    ctx.response.body = res.body;
  })).post('/joinActivity', koaBody, co.wrap(function*(ctx) {
    var reqparam = ctx.request.body
    var res = yield request
    .post(config.host+'/api/cms/activity/customerJoinActivity')
    .send({ activityId: reqparam.activityId, customerId: reqparam.customerId, customerPhone: reqparam.customerPhone })
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    ctx.response.body = res.body;
  }));
